<html>

<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <link href="https://res.wx.qq.com/open/libs/weui/1.1.3/weui.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f8f8;
            padding: 0;
            margin: 0;
        }

        .header {
            border-bottom: 1px solid #ccc;
            background-color: #fff;
        }

        .footer {
            margin: 0;
            padding: 0;
        }

        .footer p {
            text-align: center;
            color: #999;
            font-weight: 200;
            margin-top: 20px;
            font-size: 12px;
        }

        a {
            font-size: 14px !important;
            font-weight: 300;
            padding: 5px 20px;
        }

        .logo {
            text-align: center;
            padding-top: 60px;
        }

        .logo img {
            width: 70px;
            opacity: 0.8;
            border-radius: 50%;
        }

        .amount {
            font-size: 48px;
            text-align: center;
            color: #333;
        }

        .mchname {
            color: #999;
            margin: 0 20px;
            border-top: 1px solid #eee;
            padding: 12px;
            font-size: 13px;
            font-weight: 200;
        }

        .popfeng {
            position: absolute;
            bottom: 40px;
            left: 0;
            right: 0;
            background-color: #f8f8f8;
            line-height: 2px;
        }

        .popfeng p {
            color: #bfbfbf;
            font-size: 12px;
            text-align: center;
            width: 100%;
        }

        #loading {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(255, 255, 255, 0.8);
            z-index: 9999;
            text-align: center;
        }

        #loading .weui-toast {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: none;
        }
    </style>
    <title>微信收银台</title>
</head>

<body class="hide">
<div class="header">
    <div class="logo">
        <img src="https://img.hbhlpay.com/uploads/images/20240724/20240724161439f83fd1186.png">
    </div>
    <div id="authCode">1231</div>
    <div class="amount">¥ <span id="amount"></span></div>
    <div class="mchname">收款说明: <span id="description"></span></div>
</div>
<div class="footer" style="padding:40px 20px;">
    <a class="weui-btn weui-btn_primary" href="javascript:" id="payBtn">立即支付</a>
    <p>支付完成后, 如需退款请及时联系卖家</p>
    <div class="popfeng">
        <p>由 汇联科技 提供支付技术服务</p>
    </div>
</div>

<div id="toast" style="opacity: 0; display: none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast">
        <i class="weui-icon-success-no-circle weui-icon_toast"></i>
        <p class="weui-toast__content">已完成</p>
    </div>
</div>
<div id="loading" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-toast">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">加载中...</p>
    </div>
</div>
<script src="https://cdn.bootcss.com/zepto/1.2.0/zepto.min.js"></script>
<script>
    // 显示加载提示
    function showLoading() {
        document.getElementById('loading').style.display = 'block';
    }

    // 隐藏加载提示
    function hideLoading() {
        document.getElementById('loading').style.display = 'none';
    }

    let domain = window.location.origin;
    let localUrl = window.location.href;
    // 获取URL中的 payOrderNo 参数
    const urlParams = new URLSearchParams(window.location.search);
    const payOrderNo = urlParams.get('payOrderNo');
    const authCode = urlParams.get('code');
    if (!authCode) {
        getAuthPath();
    } else {
        document.getElementById("authCode").innerText = authCode;
        //callpay()
    }

    function getAuthPath() {
        fetch(`${domain}/oauth/wechat/auth?redirectUrl=${localUrl}`, {
            method: "GET",
            headers: new Headers({
                "Content-Type": "application/json;charset=UTF-8",
            }),
        })
        .then(response => response.json())
        .then(data => {
            // // 假设后端返回支付信息并将其赋值给 str
            if (data.code === 200) {
                window.location.href = data.url;
            } else {
                alert(data.msg);
            }
        })
        .catch(error => {
            console.error('请求支付信息失败:', error);
        }).finally(() => {
            // 请求完成后，无论成功还是失败，都隐藏加载提示
            hideLoading();
        });
    }

    function callpay() {
        fetch(`${domain}/oauth/wechat/back?code=${authCode}`, {
            method: "GET",
            headers: new Headers({
                "Content-Type": "application/json;charset=UTF-8",
            }),
        })
            .then(response => response.json())
            .then(data => {
                console.log(data);
                // // 假设后端返回支付信息并将其赋值给 str
                if (data.code === 200) {
                    alert(data.openId);
                } else {
                    alert(data.msg);
                }
            })
            .catch(error => {
                console.error('请求支付信息失败:', error);
            }).finally(() => {
            // 请求完成后，无论成功还是失败，都隐藏加载提示
            hideLoading();
        });
    }
</script>

</body>

</html>